package pikes.peak;

import java.util.List;
import java.util.Map;

import org.springframework.web.servlet.support.RequestContext;

import pikes.html.xhtml.list.ListItem;

public class ComponentHolder {
	private Component component = null;

	private VisibilityCondition condition = VisibilityCondition.YES;

	public ComponentHolder(final Component component) {
		this(VisibilityCondition.YES, component);
	}

	public ComponentHolder(final VisibilityCondition condition, final Component component) {
		this.condition = condition;
		this.component = component;
	}

	public final void render(List<ListItem> items, Map model, RequestContext requestContext) throws Exception {
		if (condition.isTrue(model, requestContext)) {
			items.add(new ListItem(component.createHtml(model, requestContext)));
		}
	}
}
